 package server;
 import client.MapleClient;
 import configs.ServerConfig;
 import handling.world.WorldBroadcastService;
 import java.util.*;



 import java.util.concurrent.locks.ReentrantLock;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import tools.MaplePacketCreator;

 public class AutobanManager implements Runnable {
/*  15 */   private static final Logger log = LogManager.getLogger(AutobanManager.class);
   private static final int AUTOBAN_POINTS = 5000;
/*  17 */   private static final AutobanManager instance = new AutobanManager();
/*  18 */   private final Map<Integer, Integer> points = new HashMap<>();
/*  19 */   private final Map<Integer, List<String>> reasons = new HashMap<>();
/*  20 */   private final Set<ExpirationEntry> expirations = new TreeSet<>();
/*  21 */   private final ReentrantLock lock = new ReentrantLock(true);

   public static AutobanManager getInstance() {
/*  24 */     return instance;
   }

   public void autoban(MapleClient c, String reason) {
/*  28 */     if (c.getPlayer() == null) {
       return;
     }
/*  31 */     if (c.getPlayer().isGM()) {
/*  32 */       c.getPlayer().dropMessage(5, "[警告] A/b 触发: " + reason);
/*  33 */     } else if (ServerConfig.WORLD_AUTOBAN) {
/*  34 */       addPoints(c, 5000, 0L, reason);
     } else {
/*  36 */       WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + c.getPlayer().getName() + " ID: " + c.getPlayer().getId() + " (等级 " + c.getPlayer().getLevel() + ") 游戏操作异常. (原因: " + reason + ")"));
     }
   }

   public void addPoints(MapleClient c, int points, long expiration, String reason) {
/*  41 */     this.lock.lock();

     try {
/*  44 */       int acc = c.getPlayer().getAccountID();

/*  46 */       if (this.points.containsKey(Integer.valueOf(acc))) {
/*  47 */         int SavedPoints = ((Integer)this.points.get(Integer.valueOf(acc))).intValue();
/*  48 */         if (SavedPoints >= 5000) {
           return;
         }
/*  51 */         this.points.put(Integer.valueOf(acc), Integer.valueOf(SavedPoints + points));
/*  52 */         List<String> reasonList = this.reasons.get(Integer.valueOf(acc));
/*  53 */         reasonList.add(reason);
       } else {
/*  55 */         this.points.put(Integer.valueOf(acc), Integer.valueOf(points));
/*  56 */         List<String> reasonList = new LinkedList<>();
/*  57 */         reasonList.add(reason);
/*  58 */         this.reasons.put(Integer.valueOf(acc), reasonList);
       }

/*  61 */       if (((Integer)this.points.get(Integer.valueOf(acc))).intValue() >= 5000) {
/*  62 */         log.info("[作弊] 玩家 " + c.getPlayer().getName() + " A/b 触发 " + reason);
/*  63 */         if (c.getPlayer().isGM()) {
/*  64 */           c.getPlayer().dropMessage(5, "[警告] A/b 触发 : " + reason);
           return;
         }
/*  67 */         StringBuilder sb = new StringBuilder("A/b ");
/*  68 */         sb.append(c.getPlayer().getName());
/*  69 */         sb.append(" (IP ");
/*  70 */         sb.append(c.getSessionIPAddress());
/*  71 */         sb.append("): ");
/*  72 */         for (String s : this.reasons.get(Integer.valueOf(acc))) {
/*  73 */           sb.append(s);
/*  74 */           sb.append(", ");
         }
/*  76 */         WorldBroadcastService.getInstance().broadcastMessage(MaplePacketCreator.serverNotice(0, " <" + c.getPlayer().getName() + "> 被系统封号 (原因: " + reason + ")"));
/*  77 */         c.getPlayer().ban(sb.toString(), false, true, false);
       }
/*  79 */       else if (expiration > 0L) {
/*  80 */         this.expirations.add(new ExpirationEntry(System.currentTimeMillis() + expiration, acc, points));
       }
     } finally {

/*  84 */       this.lock.unlock();
     }
   }


   public void run() {
/*  90 */     long now = System.currentTimeMillis();
/*  91 */     for (ExpirationEntry e : this.expirations) {
/*  92 */       if (e.time <= now) {
/*  93 */         this.points.put(Integer.valueOf(e.acc), Integer.valueOf(((Integer)this.points.get(Integer.valueOf(e.acc))).intValue() - e.points));
         continue;
       }
       return;
     }
   }

   private static class ExpirationEntry
     implements Comparable<ExpirationEntry> {
     public final long time;
     public final int acc;
     public final int points;

     public ExpirationEntry(long time, int acc, int points) {
/* 107 */       this.time = time;
/* 108 */       this.acc = acc;
/* 109 */       this.points = points;
     }


     public int compareTo(ExpirationEntry o) {
/* 114 */       return (int)(this.time - o.time);
     }


     public boolean equals(Object oth) {
/* 119 */       if (!(oth instanceof ExpirationEntry)) {
/* 120 */         return false;
       }
/* 122 */       ExpirationEntry ee = (ExpirationEntry)oth;
/* 123 */       return (this.time == ee.time && this.points == ee.points && this.acc == ee.acc);
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\AutobanManager.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */